package com.demo2do.boyle.client.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.boyle.client.service.AdvertisementService;
import com.demo2do.boyle.common.entity.advertisement.Advertisement;
import com.demo2do.boyle.common.entity.customer.social.SocialType;
import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.service.impl.GenericServiceImpl;
import com.demo2do.core.web.resolver.Page;

/**
 * 
 * @author mohanlan
 *
 */
@Service("advertisementService")
public class AdvertisementServiceImpl extends GenericServiceImpl<Advertisement> implements AdvertisementService {
	
	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.boyle.client.service.AdvertisementService#list(com.demo2do.core.web.resolver.Page)
	 */
	public List<Advertisement> list(Page page) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Advertisement> listByTest(Page page,SocialType socialType) {
		
		String sentence = " FROM Advertisement advertisement WHERE advertisement.id in :ids ";
		
		Map<String, Object> parameters = new HashMap<String, Object>();
		//TODO
		parameters.put("ids", new Object[]{57,58,59,60,61,62});
		
		if(socialType != null) {
			parameters.put("socialType", socialType);
			sentence = sentence + " AND advertisement.socialType = :socialType ";
		}
		
		List<Advertisement> advertisements = genericDaoSupport.searchForList(sentence, parameters);
		
		return advertisements;
	}

}
